package tau.adx.common.bids.bundles;

import java.util.Map;

import lombok.AllArgsConstructor;
import lombok.Data;
import tau.adx.common.adn.AdNetwork;
import tau.adx.common.bids.BidInfo;
import tau.adx.common.bids.BidTarget;
import tau.adx.common.publishers.AdxPublisher;
import tau.adx.common.users.AdxUser;

/**
 * Mapping between {@link BidTarget}s and
 * {@link edu.umich.eecs.tac.props.BidBundle.BidEntry} to be handed by an
 * {@link AdNetwork} to the <b>AdX</b> system.
 * 
 * @author greenwald
 * 
 */
@AllArgsConstructor
@Data
public class AdxBidBundle {

	/**
	 * Mapping between {@link BidTarget}s and {@link BidEntry} to be handed by
	 * an {@link AdNetwork} to the <b>AdX</b> system.
	 */
	private final Map<BidTarget, BidInfo> bundles;

	/**
	 * Associated {@link AdNetwork}.
	 */
	private final AdNetwork adNetwork;

	/**
	 * Adds a bid to {@link #bundles bid map}.
	 * 
	 * @param bidTarget
	 *            {@link BidTarget} to add.
	 * @param bid
	 *            {@link edu.umich.eecs.tac.props.BidBundle.BidEntry} to add.
	 */
	public void add(BidTarget bidTarget, BidInfo bid) {
		bundles.put(bidTarget, bid);
	}

	/**
	 * Returns a {@link BidEntry} according to given parameters.
	 * 
	 * @param user
	 *            {@link AdxUser}.
	 * @param publisher
	 *            {@link AdxPublisher}.
	 * @param ignoreMinorAttributes
	 *            Indicates whether minor attributes, such as {@link AdxUser}'s
	 *            pContinue, should be set to default value.
	 * @return A {@link BidEntry} according to given parameters.
	 */
	public BidInfo getBidEntry(AdxUser user, AdxPublisher publisher,
			boolean ignoreMinorAttributes) {
		AdxUser bidUser;
		if (ignoreMinorAttributes) {
			bidUser = ((AdxUser) user.clone()).ignoreMinorAttributes();
		} else {
			bidUser = user;
		}
		return bundles.get(new BidTarget(bidUser, publisher));
	}

}
